home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / DATE.H < prev    next >
C/C++ Source or Header  |  1993-04-27  |  4KB  |  99 lines

  1. #ifndef DATE_H
  2. #define DATE_H
  3.  
  4. #include "object.h"
  5.  
  6. typedef unsigned short dayTy;
  7. typedef unsigned short monthTy;
  8. typedef unsigned short yearTy;
  9.  
  10. extern const Class class_Date;
  11.  
  12. dayTy       dayOfWeek(const char* dayName);
  13. dayTy       daysInYear(yearTy year);
  14. monthTy     numberOfMonth(const char* monthName);
  15. bool        leapYear(yearTy year);
  16. const char* nameOfMonth(monthTy monthNumber);
  17. const char* nameOfDay(dayTy weekDayNumber);
  18.  
  19. ////////////////////////////////////////////////////////////
  20. // class Date (declaration)
  21. ////////////////////////////////////////////////////////////
  22. class Date: public Object {
  23.     dayTy   dy;         // day of year
  24.     yearTy  yr;         // year
  25.     void    setDate(int,yearTy);
  26. public:
  27.             ////////////////////////
  28.             ///// constructors 
  29.             ////////////////////////
  30.             Date(const Date& date)          { dy=date.dy; yr=date.yr;}
  31.             Date& operator=(const Date& date)
  32.                                             { dy=date.dy; 
  33.                                               yr=date.yr; 
  34.                                               return *this; 
  35.                                             }
  36.             Date();                         // current date
  37.             Date(long dayCount);
  38.             Date(int dayCount, yearTy referenceYear);
  39.             Date(dayTy newDay, const char* monthName, yearTy newYear);
  40.             Date(istream&);                 // read date from stream
  41.  
  42.                 ////////////////////////
  43.                 // operators
  44.                 ////////////////////////
  45.     bool        operator<(Date)         const;
  46.     bool        operator<=(Date)        const;
  47.     bool        operator>(Date date)    const   { return date < *this; }
  48.     bool        operator>=(Date date)   const   { return date <= *this; }
  49.     bool        operator==(Date date)   const   {
  50.                                                   return dy == date.dy
  51.                                                   && yr == date.yr;
  52.                                                 }
  53.     bool        operator!=(Date date)   const   {
  54.                                                   return dy != date.dy
  55.                                                   || yr != date.yr;
  56.                                                 }
  57.  
  58.     friend Date operator+(Date dt, int dd)      { return Date(dt.dy+dd, dt.yr); }
  59.     friend Date operator+(int dd, Date dt)      { return Date(dt.dy+dd, dt.yr); }
  60.  
  61.     long        operator-(Date dt)      const;
  62.     Date        operator-(int dd)       const   { return Date(dy-dd, yr); }
  63.     void        operator+=(int dd)              { setDate(dy+dd, yr); }
  64.     void        operator-=(int dd)              { setDate(dy-dd, yr); }
  65.  
  66.             
  67.                 ////////////////////////
  68.                 // member functions
  69.                 ////////////////////////
  70.     bool        between(Date, Date)     const;
  71.     dayTy       day()                   const   { return dy; }
  72.     dayTy       dayOfMonth()            const;
  73.     dayTy       firstDayOfMonth()       const   {
  74.                                                   return
  75.                                                   firstDayOfMonth(month());
  76.                                                 }
  77.     dayTy       firstDayOfMonth(monthTy month) const;
  78.     bool        leap()                  const   { return leapYear(yr); }
  79.     Date        max(Date)               const;
  80.     Date        min(Date)               const;
  81.     monthTy     month()                 const;
  82.     const char* nameOfMonth()           const;
  83.     Date        previous(const char* dayName) const;
  84.     dayTy       weekDay()               const;
  85.     yearTy      year()                  const   { return yr; }
  86.  
  87.     virtual int             compare(const Object&)  const;
  88.     virtual Object*         copy()                  const;
  89.     virtual void            deepenShallowCopy();
  90.     virtual unsigned        hash()                  const;
  91.     virtual const Class*    isA()                   const;
  92.     virtual bool            isEqual(const Object&)  const;
  93.     virtual void            printOn(ostream& strm)  const;
  94.     virtual void            scanFrom(istream& strm);
  95.     virtual const Class*    species()               const;
  96. };
  97.  
  98. #endif
  99.